<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <link rel="stylesheet" type="text/css" href="../../asset/jquery-easyui-1.5.5.2/themes/default/easyui.css">
    <link rel="stylesheet" type="text/css" href="../../asset/jquery-easyui-1.5.5.2/themes/icon.css">
    <script type="text/javascript" src="../../asset/jquery-easyui-1.5.5.2/jquery.min.js"></script>
    <script type="text/javascript" src="../../asset/jquery-easyui-1.5.5.2/jquery.easyui.min.js"></script>
    <script type="text/javascript" src="../../asset/jquery-easyui-1.5.5.2/locale/easyui-lang-zh_CN.js"></script>
    <script type="text/javascript">
        var url;
        function searchMessage() {
            $("#dg").datagrid('load',{
                messageContent:$("#m_messageContent").val()
            });
        }

        function deleteMessage() {
            var selectedRows=$("#dg").datagrid('getSelections');
            if(selectedRows.length==0){
                $.messager.alert("系统提示","请选择要删除的数据！");
                return;
            }
            var strIds=[];
            for(var i=0;i<selectedRows.length;i++){
                strIds.push(selectedRows[i].messageId);
            }
            var ids=strIds.join(",");
            $.messager.confirm("系统提示","您确认要删掉这<font color=red>"+selectedRows.length+"</font>条数据吗？",function(r){
                if(r){
                    $.post("MessageDeleteAction.action",{delIds:ids},function(result){
                        if(result.success){
                            $.messager.alert("系统提示","您已成功删除<font color=red>"+result.delNums+"</font>条数据！");
                            $("#dg").datagrid("reload");
                        }else{
                            $.messager.alert('系统提示','<font color=red>'+selectedRows[result.errorIndex].messageContent+'</font>'+result.errorMsg);
                        }
                    },"json");
                }
            });
        }
        function openMessageAddDialog(){
            resetValue();
            $("#dlg").dialog("open").dialog("setTitle","添加留言信息");
            url="MessageSaveAction.action";
        }

        function saveMessage(){
            $("#fm").form("submit",{
                url:url,
                onSubmit:function(){
                    return $(this).form("validate");
                },
                success:function(result){
                    if(result.errorMsg){
                        $.messager.alert("系统提示",result.errorMsg);
                        return;
                    }else{
                        $.messager.alert("系统提示","保存成功");
                        resetValue();
                        $("#dlg").dialog("close");
                        $("#dg").datagrid("reload");
                    }
                }
            });
        }

        function resetValue(){
            $("#messageContent").val("");
            $("#messageDate").datebox("setValue","");
            $("#userId").combobox("setValue","");

        }

        function closeMessageDialog(){
            $("#dlg").dialog("close");
            resetValue();
        }

        function openMessageModifyDialog(){
            var selectedRows=$("#dg").datagrid('getSelections');
            if(selectedRows.length!=1){
                $.messager.alert("系统提示","请选择一条要编辑的数据！");
                return;
            }
            var row=selectedRows[0];
            $("#dlg").dialog("open").dialog("setTitle","编辑留言信息");
            $("#messageContent").val(row.messageContent);
            $("#messageDate").datebox("setValue",row.messageDate);
            $("#userId").combobox("setValue",row.userId);
            url="MessageSaveAction.action?messageId="+row.messageId;
        }
    </script>
</head>
<body style="margin: 5px;">
<table id="dg" title="留言信息" class="easyui-datagrid" fitColumns="true"
       pagination="true" rownumbers="true" url="MessageFindAction.action" fit="true" toolbar="#tb">
    <thead>
    <tr>
        <th field="cb" width="30" checkbox="true"></th>
        <th field="messageId" width="30"  align="center">编号</th>
        <th field="messageContent" width="200" align="center">内容</th>
        <th field="messageDate" width="50" align="center">留言时间</th>
        <th field="UserId" width="30" align="center" >留言用户Id</th>
        <th field="UserName" width="30" align="center" >留言用户</th>
    </tr>
    </thead>
</table>

<div id="tb">
    <div>
        <a href="javascript:openMessageAddDialog()" class="easyui-linkbutton" iconCls="icon-add" plain="true">添加</a>
        <a href="javascript:openMessageModifyDialog()" class="easyui-linkbutton" iconCls="icon-edit" plain="true">修改</a>

        <a href="javascript:deleteMessage()" class="easyui-linkbutton" iconCls="icon-remove" plain="true">删除</a>
    </div>
    <div>&nbsp;留言内容：&nbsp;<input type="text" name="messageContent" id="m_messageContent" size="10"/>
        <a href="javascript:searchMessage()" class="easyui-linkbutton" iconCls="icon-search" plain="true">搜索</a>
    </div>
    <div id="dlg" class="easyui-dialog" style="width: 570px;height: 350px;padding: 10px 20px"
         closed="true" buttons="#dlg-buttons">
        <form id="fm" method="post">
            <table cellspacing="5px;">
                <tr>
                    <td>内容：</td>
                    <td><input type="text" name="message.messageContent" id="messageContent" class="easyui-validatebox" required="true"/></td>
                </tr>
                <tr>
                    <td>留言日期：</td>
                    <td><input class="easyui-datebox" name="message.messageDate" id="messageDate" required="true" editable="false" /></td>
                </tr>
                <tr>
                    <td>所属用户：</td>
                    <td><input class="easyui-combobox" id="userId" name="message.mUserId"  data-options="panelHeight:'auto',editable:false,valueField:'id',textField:'userName',url:'UserComboListAction.action'"/></td>
                </tr>
            </table>
        </form>
    </div>
    <div id="dlg-buttons">
        <a href="javascript:saveMessage()" class="easyui-linkbutton" iconCls="icon-ok">保存</a>
        <a href="javascript:closeMessageDialog()" class="easyui-linkbutton" iconCls="icon-cancel">关闭</a>
    </div>
</div>
</body>
</html>